package com.ruoyi.web.controller.glue;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.GlueCategory;
import com.ruoyi.system.service.IGlueCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 选胶分类
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Validated
@RestController
@RequestMapping("/system/category")
public class GlueCategoryController extends BaseController
{
    @Autowired
    private IGlueCategoryService glueCategoryService;

    /**
     * 查询选胶分类列表
     * @return {@link GlueCategory}
     */
    //@PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(GlueCategory glueCategory)
    {
        List<GlueCategory> list = glueCategoryService.selectGlueCategoryList(glueCategory);
        return getDataTable(list);
    }

    /**
     * 导出选胶分类列表
     */
    //@PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "选胶分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GlueCategory glueCategory)
    {
        List<GlueCategory> list = glueCategoryService.selectGlueCategoryList(glueCategory);
        ExcelUtil<GlueCategory> util = new ExcelUtil<GlueCategory>(GlueCategory.class);
        util.exportExcel(response, list, "选胶分类数据");
    }

    /**
     * 获取选胶分类详细信息
     * @return {@link GlueCategory}
     */
    //@PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(glueCategoryService.selectGlueCategoryById(id));
    }

    /**
     * 新增选胶分类
     */
    //@PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "选胶分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GlueCategory glueCategory)
    {
        return toAjax(glueCategoryService.insertGlueCategory(glueCategory));
    }

    /**
     * 修改选胶分类
     */
    //@PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "选胶分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GlueCategory glueCategory)
    {
        return toAjax(glueCategoryService.updateGlueCategory(glueCategory));
    }

//    /**
//     * 删除选胶分类
//     */
//    //@PreAuthorize("@ss.hasPermi('system:category:remove')")
//    @Log(title = "选胶分类", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(glueCategoryService.deleteGlueCategoryByIds(ids));
//    }


    /**
     * 删除选胶分类单个
     */
    //@PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "选胶分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(glueCategoryService.deleteGlueCategoryById(id));
    }




}
